use sea_orm::{ActiveModelTrait, EntityTrait};
use sea_orm::ActiveValue::Set;

use common::ctx::get_db_by_key;
use common::error::MyError;
use entity::charac_view;
use entity::prelude::CharacView;


pub struct CharacViewManager {}

impl CharacViewManager {
    pub async fn set_max_role(uid: u32) -> Result<bool, MyError> {
        let entity = CharacView::find_by_id(uid)
            .one(&*get_db_by_key("taiwan_cain")?)
            .await?
            .ok_or(MyError::ServerError(format!(
                "charac_view [{:?}] does not exist",
                uid
            )))?;
        let mut entity: charac_view::ActiveModel = entity.into();
        entity.charac_count = Set(24);
        entity.charac_slot_limit = Set(24);
        let _result = entity.update(&*get_db_by_key("taiwan_cain")?).await?;
        Ok(true)
    }
}